package com.cn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.api.ApiCode;
import com.cn.api.ApiResult;
import com.cn.mapper.ShopCommodityMapper;
import com.cn.pojo.DTO.ShopCommodityDTO;
import com.cn.pojo.shop.ShopCommodity;
import com.cn.pojo.vo.ShopCommodityVo;
import com.cn.service.ShopCommentService;
import com.cn.service.ShopCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 28631
* @description 针对表【shop_commodity(商品表)】的数据库操作Service实现
* @createDate 2024-02-29 15:12:20
*/
@Service
public class ShopCommodityServiceImpl extends ServiceImpl<ShopCommodityMapper, ShopCommodity>
    implements ShopCommodityService {


    @Autowired
    private ShopCommodityMapper shopCommodityMapper;

    /**
     * 查询商品数据信息
     * @return
     */
    @Override
    public ApiResult queryCommodity() {
        List<ShopCommodityDTO> shopCommodities = shopCommodityMapper.queryCommodity(null);
        return ApiResult.success(shopCommodities);
    }

    /**
     * 修改商品
     * @param shopCommodity
     * @return
     */
    @Override
    public ApiResult updateCommodity(ShopCommodity shopCommodity,Integer id) {
        shopCommodity.setCtcId(id);
        int i = shopCommodityMapper.updateById(shopCommodity);
        return ApiResult.success(ApiCode.SUCCESS);
    }

    /**
     * 删除项目信息
     * @param id
     * @return
     */
    @Override
    public ApiResult deleteCommodity(Integer id) {
        int i = shopCommodityMapper.deleteById(id);
        return ApiResult.success(ApiCode.SUCCESS);
    }

    /**
     * 增加商品信息
     * @param shopCommodity 商品
     * @return
     */
    @Override
    public ApiResult addCommodity(ShopCommodityVo shopCommodity) {
        shopCommodity.setCtcId(shopCommodity.getCtcId());
        shopCommodity.setCreateTime(new Date());
        shopCommodity.setCreatePerson("yh");
        int insert = shopCommodityMapper.insert(shopCommodity);
        return ApiResult.success(ApiCode.SUCCESS);
    }

    /**
     * 查询商品信息
     * @return
     */
    @Override
    public ApiResult selectCommodity() {
        List<ShopCommodity> shopCommodities  = shopCommodityMapper.selectCommodity();
        return ApiResult.success(shopCommodities);
    }


}




